﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClientControllers;
using ClientInterfaces;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Threading;
using System.Windows.Threading;
using System.ComponentModel;

namespace WilkeGruppe4
{
    public partial class MainWindow : Window
    {
        Cls_Controller systemController;
        PasswordWindow passwordWindow;
        DispatcherTimer dispatcherTimer;
        CancelEventArgs closeEvent;
        string currentPassword;

        public MainWindow()
        {
            InitializeComponent();
            systemController = new Cls_Controller();
            passwordWindow = new PasswordWindow(this, systemController);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatchTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 3);
            dispatcherTimer.Start();
            systemController.BlockTaskManager();
            systemController.HideTaskBar();
        }

        void dispatchTimer_Tick(object sender, EventArgs e)
        {
            systemController.KillProcesses();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            closeEvent = e;
            closeEvent.Cancel = true;

            passwordWindow.ShowDialog();
        }

        public bool CheckPassword(string inputPassword)
        {
            try
            {
                currentPassword = systemController.GetCurrentPassword();

                if (inputPassword == currentPassword)
                {
                    closeEvent.Cancel = false;
                    return true;
                }
                else
                {
                    MessageBox.Show("Wrong Password!", "Wrong Password!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }

        private void Window_IsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            this.Activate();
        }
    }
}
